package com.member.spring_cloud_member;


import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import javax.servlet.http.HttpServletRequest;

import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.member.entity.Member;


@RestController
public class MemberController {

//	private static List<Member> members;
//	
//	
//	static{
//		members.add(new Member(1, "carmen", "carmen_message"));
//		members.add(new Member(2, "mike", "mike_message"));
//		members.add(new Member(3, "kitty", "kitty_message"));
//	}
	
	
	
	@RequestMapping(value="/id/{id}",method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
	public Member findMemberById(@PathVariable("id") Integer id,HttpServletRequest request){
		List<Member>list=getList();
		for (Member member : list) {
			if(member.getM_id().equals(id)){
				member.setM_message(request.getRequestURL().toString());
				return member;
			}
		}
		return null;
	}
	
	
	private List<Member> getList(){
		List<Member> members=new ArrayList<>();
		members.add(new Member(1, "carmen", "carmen_message"));
		members.add(new Member(2, "mike", "mike_message"));
		members.add(new Member(3, "kitty", "kitty_message"));
		return members;
	}
	
	
}
